package info.heidao.ww2.common.jackson;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.IOException;

/**
 * @author: zhengheng
 * @Date: 2021-08-03 19:57
 * @Description:
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class LongToDateSerializer extends JsonSerializer<Long> {

    @Override
    public void serialize(Long timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(DateUtil.format(new DateTime(timestamp * 1000), DatePattern.NORM_DATETIME_PATTERN));
    }
}
